#include<stdio.h>
#include<conio.h>
int a[1000],trace[1000],i,j,n,max,temp,s;
void input(){
    FILE *fp=fopen("DAYCON.INP","r");
    fscanf(fp,"%d%d",&s,&n);
    for(i=1;i<=n;i++){
        fscanf(fp,"%d",&a[i]);
    }
    fclose(fp);
}
void process(){
    temp=0;
    for(i=1;i<=n;i++){
        max=temp;
        for(j=0;j<=max;j++){
            if(j+a[i]>s)continue;
            if((j==0 || trace[j]!=0) && trace[j+a[i]]==0){
                trace[j+a[i]]=a[i];
                if(j+a[i]>temp)temp=j+a[i];
                if(j+a[i]==s)return;
            }
        }
    }
}
void output(){
    if(trace[s]==0)printf("NOWAY");
    else{
        do{
            printf("%d ",trace[s]);
            s=s-trace[s];
        }while(trace[s]>0);
    }
}
int main(){
    input();
    process();
    output();
    getch();
    return 0;
}
                
            
    

